namespace Pp.UI.Models
{
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Linq;
    using System.Linq.Expressions;
    using System.Reflection;
    using System.Text;
    using System.Threading;
    using System.Web.Mvc;
    using System.Web.Mvc.Html;
    using System.Web.Routing;
    using System.Text.RegularExpressions;
    using Core.Extentions;
    using Dto.Validators;
    using global::Ilgera.TMS.UI.Web.Helpers;
    using Globalization;
    public static class HtmlHelpers
    {
        #region Property or Action to Name
        public static string GetPropertyName<T>(this HtmlHelper helper, Expression<Func<T, object>> member) where T : class
        {
            return ExpressionHelper.GetPropertyName(member);
        }

        public static string GetMethodName<T>(this HtmlHelper helper, Expression<Func<T, object>> action) where T : Controller
        {
            return ExpressionHelper.GetMethodName(action);
        }

        public static string GetMethodName<T>(this HtmlHelper helper, Expression<Action<T>> action) where T : Controller
        {
            return ExpressionHelper.GetMethodName(action);
        }
        #endregion

        #region ActionLink
        public static string ActionLink<T>(this HtmlHelper helper, Expression<Action<T>> action, string linkText,
            RouteValueDictionary routeValues) where T : Controller
        {
            return helper.ActionLink(action, linkText, null, routeValues);
        }

        public static string ActionLink<T>(this HtmlHelper helper, Expression<Action<T>> action, string linkText,
            IDictionary<string, object> htmlAttributes, RouteValueDictionary routeValues) where T : Controller
        {
            var actionInfo = ExpressionHelper.GetActionInfo(action);

            return helper.ActionLink(linkText, actionInfo.ActionName, actionInfo.ControllerName, routeValues, htmlAttributes).ToHtmlString();
        }
        #endregion

        #region Custom submit button
        private const string SUBMIT_BUTTON_FORMAT =
            "<div class=\"looseDoubleTop\"><input id=\"{0}\" name=\"{0}\" type=\"submit\" value=\"{1}\" class=\"btn{2}\"{2} /></div>";

        public static string Submit(this HtmlHelper helper, string buttonText, bool disabled)
        {
            return Submit(helper, SiteConstants.DEFAULT_SUBMIT_BUTTON_NAME, buttonText, disabled);
        }

        public static string Submit(this HtmlHelper helper, string name, string buttonText, bool disabled)
        {
            return SUBMIT_BUTTON_FORMAT.FormatWith(name, buttonText, disabled ? " disabled" : string.Empty);
        }
        #endregion

        #region TextBox
        public static string TextBox<T>(this HtmlHelper helper, Expression<Func<T, object>> property)
        {
            return TextBox(helper, property, null, null, null, null, null);
        }
        public static string TextBox<T>(this HtmlHelper helper, Expression<Func<T, object>> property, IDictionary<string, object> htmlAttributes)
        {
            return TextBox(helper, property, htmlAttributes, null);
        }
        public static string TextBox<T>(this HtmlHelper helper, Expression<Func<T, object>> property, IDictionary<string, object> htmlAttributes, object deafult)
        {
            return TextBox(helper, property, null, null, deafult, htmlAttributes, TextBoxSize.Medium);
        }
        public static string TextBox<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string labelText)
        {
            return TextBox(helper, property, null, labelText, null, null, TextBoxSize.Medium);
        }
        public static string TextBox<T>(this HtmlHelper helper, string labelText, Expression<Func<T, object>> property)
        {
            return TextBox(helper, property, null, labelText, null, null, TextBoxSize.Medium);
        }
        public static string Password<T>(this HtmlHelper helper, string labelText, Expression<Func<T, object>> property)
        {
            return Password(helper, property, null, labelText, null, null, TextBoxSize.Medium);
        }
        public static string TextBox<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string labelText, IDictionary<string, object> htmlAttributes)
        {
            return TextBox(helper, property, null, labelText, null, htmlAttributes, TextBoxSize.Medium);
        }
        public static string TextBox<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string labelText, object value)
        {
            return TextBox(helper, property, null, labelText, value, null, TextBoxSize.Medium);
        }

        public static string TextBox<T>(this HtmlHelper helper, string nameSuffix, Expression<Func<T, object>> property, string labelText)
        {
            return TextBox(helper, property, nameSuffix, labelText, null, null, TextBoxSize.Medium);
        }

        public static string TextBox<T>(this HtmlHelper helper, string nameSuffix, Expression<Func<T, object>> property, string labelText, object value)
        {
            return TextBox(helper, property, nameSuffix, labelText, value, null, TextBoxSize.Medium);
        }

        public static string TextBox<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string labelText,
            object value, IDictionary<string, object> htmlAttributes)
        {
            return TextBox(helper, property, null, labelText, value, htmlAttributes, TextBoxSize.Medium);
        }

        public static string TextBox<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string labelText, TextBoxSize size)
        {
            return TextBox(helper, property, null, labelText, null, null, size);
        }

        public static string TextBox<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string labelText, object value, TextBoxSize size)
        {
            return TextBox(helper, property, null, labelText, value, null, size);
        }


        public static string TextBox<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string nameSuffix, string labelText,
           object value, IDictionary<string, object> htmlAttributes, TextBoxSize? size)
        {
            return TextBox(helper, null, property, nameSuffix, labelText, value, htmlAttributes, size);
        }
        public static string Password<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string nameSuffix, string labelText,
          object value, IDictionary<string, object> htmlAttributes, TextBoxSize? size)
        {
            return Password(helper, null, property, nameSuffix, labelText, value, htmlAttributes, size);
        }

        public static string TextBox<T>(this HtmlHelper helper, string namePrefix, Expression<Func<T, object>> property, string nameSuffix,

                                        object value, IDictionary<string, object> htmlAttributes, TextBoxSize? size)
        {
            return TextBox(helper, namePrefix, property, nameSuffix, null, value, htmlAttributes, size);
        }


        public static string TextBox<T>(this HtmlHelper helper, string namePrefix, Expression<Func<T, object>> property, string nameSuffix, string labelText,
          object value, IDictionary<string, object> htmlAttributes, TextBoxSize? size)
        {
            var info = ExpressionHelper.GetMemberInfo(property) as PropertyInfo;
            if (info == null) throw new ArgumentException("Member is not a property");

            var stringBuilder = new StringBuilder();
            var classValues = new string[2];
            var attributes = info.GetCustomAttributes(true);
            classValues[0] = GetMetadata(attributes);
            if (size.HasValue)
                classValues[1] = size.ToString().ToLowerInvariant();

            htmlAttributes = PopulateClass(htmlAttributes, classValues);
            stringBuilder.Append(helper.TextBox(namePrefix + info.Name + nameSuffix, value, htmlAttributes));
            stringBuilder.Append(helper.ValidationMessage(namePrefix + info.Name + nameSuffix));

            return Render(stringBuilder.ToString(), labelText, namePrefix + info.Name + nameSuffix);
        }
        public static string Password<T>(this HtmlHelper helper, string namePrefix, Expression<Func<T, object>> property, string nameSuffix, string labelText,
         object value, IDictionary<string, object> htmlAttributes, TextBoxSize? size)
        {
            var info = ExpressionHelper.GetMemberInfo(property) as PropertyInfo;
            if (info == null) throw new ArgumentException("Member is not a property");

            var stringBuilder = new StringBuilder();
            var classValues = new string[2];
            var attributes = info.GetCustomAttributes(true);
            classValues[0] = GetMetadata(attributes);
            if (size.HasValue)
                classValues[1] = size.ToString().ToLowerInvariant();

            htmlAttributes = PopulateClass(htmlAttributes, classValues);
            stringBuilder.Append(helper.Password(namePrefix + info.Name + nameSuffix, value, htmlAttributes));
            stringBuilder.Append(helper.ValidationMessage(namePrefix + info.Name + nameSuffix));

            return Render(stringBuilder.ToString(), labelText, namePrefix + info.Name + nameSuffix);
        }
        #endregion

        #region Label Span
        public static string LabelSpan(this HtmlHelper helper, string labelText, string valueText)
        {
            return "<div class='looseTop'><label>{0}</label><span>{1}&nbsp;</span></div>".FormatWith(labelText, valueText);
        }

        public static string LabelSpan(this HtmlHelper helper, string labelText, string valueText, string valueLabelId)
        {
            return "<div class='looseTop'><label>{0}</label><span id='{2}' name='{2}'>{1}</span></div>".FormatWith(labelText, valueText, valueLabelId);
        }
        #endregion

        #region TextArea
        public static string TextArea<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string labelText)
        {
            return TextArea(helper, property, string.Empty, labelText, null, null, false);
        }
        public static string TextArea<T>(this HtmlHelper helper, Expression<Func<T, object>> property)
        {
            return TextArea(helper, property, string.Empty, null, null, null, false);
        }

        public static string TextArea<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string labelText, object value)
        {
            return TextArea(helper, property, string.Empty, labelText, value, null, false);
        }

        public static string TextArea<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string nameSuffix, string labelText, object value)
        {
            return TextArea(helper, property, nameSuffix, labelText, value, null, false);
        }

        public static string TextArea<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string labelText, object value,
            IDictionary<string, object> htmlAttributes)
        {
            return TextArea(helper, property, string.Empty, labelText, value, htmlAttributes, false);
        }

        public static string TextArea<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string nameSuffix, string labelText, object value,
            IDictionary<string, object> htmlAttributes)
        {
            return TextArea(helper, property, nameSuffix, labelText, value, htmlAttributes, false);
        }

        public static string TextArea<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string nameSuffix, string labelText, object value,
            IDictionary<string, object> htmlAttributes, bool makeWysiwyg)
        {
            var info = ExpressionHelper.GetMemberInfo(property) as PropertyInfo;
            if (info == null) throw new ArgumentException("Member is not a property");

            var stringBuilder = new StringBuilder();
            var classValues = new string[2];
            var attributes = info.GetCustomAttributes(true);
            classValues[0] = GetMetadata(attributes);
            if (makeWysiwyg)
                classValues[1] = "wysiwyg";
            htmlAttributes = PopulateClass(htmlAttributes, classValues);

            stringBuilder.Append(helper.TextArea(info.Name + nameSuffix, value != null ? value.ToString() : null, htmlAttributes));
            stringBuilder.Append(helper.ValidationMessage(info.Name + nameSuffix, new { htmlfor = info.Name + nameSuffix, generated = true }));

            return Render(stringBuilder.ToString(), labelText, info.Name + nameSuffix);
        }
        #endregion

        #region CheckBox
        public static string CheckBox<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string labelText, string trueStr, string falseStr)
        {
            return CheckBox(helper, property, labelText, false, trueStr, falseStr);
        }
        public static string CheckBox<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string labelText, bool value, string trueStr, string falseStr)
        {
            return CheckBox(helper, property, labelText, value, trueStr, falseStr, null);
        }

        public static string CheckBox<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string labelText, bool value, string trueStr, string falseStr,
            IDictionary<string, object> htmlAttributes)
        {
            return CheckBox(helper, null, property, null, labelText, value, trueStr, falseStr, htmlAttributes);
        }

        public static string CheckBox<T>(this HtmlHelper helper, string namePrefix, Expression<Func<T, object>> property, string nameSuffix, string labelText, bool value, string trueStr, string falseStr,
            IDictionary<string, object> htmlAttributes)
        {
            var info = ExpressionHelper.GetMemberInfo(property) as PropertyInfo;
            if (info == null) throw new ArgumentException("Member is not a property");

            var stringBuilder = new StringBuilder();
            var classValues = new string[1];
            classValues[0] = GetMetadata(info.GetCustomAttributes(true));
            htmlAttributes = PopulateClass(htmlAttributes, classValues);

            var name = namePrefix + info.Name + nameSuffix;
            stringBuilder.Append(helper.CheckBox(name, value, htmlAttributes));
            stringBuilder.Append("<div class='ckbInfo checkInfo" + name + "'>" + (value ? trueStr : falseStr) + "</div><script>$('#" + name + "').change(function(){if ($(this).attr('checked')){$(this).parent().find('div.checkInfo" + name + "').text('" + trueStr + "');}else{$(this).parent().find('div.checkInfo" + name + "').text('" + falseStr + "');}});</script>");
            stringBuilder.Append(helper.ValidationMessage(namePrefix + info.Name + nameSuffix, new { htmlfor = namePrefix + info.Name + nameSuffix, generated = true }));

            return Render(stringBuilder.ToString(), labelText, namePrefix + info.Name + nameSuffix);
        }

        #endregion

        #region FileUpload
        // 
        public static string FileUploader<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string nameSuffix, string labelText, UploadType uploadType)
        {
            return FileUploader(helper, property, nameSuffix, labelText, null, null, uploadType);
        }
        public static string FileUploader<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string labelText, UploadType uploadType)
        {
            return FileUploader(helper, property, null, labelText, null, null, uploadType);
        }
        public static string FileUploader<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string labelText, object value, UploadType uploadType)
        {
            return FileUploader(helper, property, null, labelText, value, null, uploadType);
        }

        public static string FileUploader<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string nameSuffix, string labelText,
            object value, IDictionary<string, object> htmlAttributes, UploadType uploadType)
        {
            var info = ExpressionHelper.GetMemberInfo(property) as PropertyInfo;
            if (info == null) throw new ArgumentException("Member is not a property");
            nameSuffix = nameSuffix ?? string.Empty;

            string metadata = GetMetadata(info.GetCustomAttributes(true));

            if (htmlAttributes == null || htmlAttributes.Count == 0)
                htmlAttributes = new Dictionary<string, object> { { "class", "{0}".FormatWith(metadata) } };
            else
            {
                if (htmlAttributes.ContainsKey("class"))
                    htmlAttributes["class"] = "{0} {1}".FormatWith(htmlAttributes["class"], metadata);
                else
                    htmlAttributes.Add("class", "{0}".FormatWith(metadata));
            }
            if (uploadType == UploadType.File)
            {
                htmlAttributes.Add("accept", "pdf|rar|zip|doc|xls");
            }
            else if (uploadType == UploadType.Image)
            {
                htmlAttributes.Add("accept", "png|jpe?g|gif");
            }
            var fullName = info.Name + nameSuffix;
            var tagBuilder = new TagBuilder("input");
            tagBuilder.MergeAttribute("type", @"file");
            tagBuilder.GenerateId(fullName);
            tagBuilder.MergeAttribute("name", fullName);
            tagBuilder.MergeAttributes(htmlAttributes);

            if (value != null)
                tagBuilder.MergeAttribute("value", value.ToString());

            return Render(tagBuilder.ToString(TagRenderMode.SelfClosing) +
                helper.ValidationMessage(fullName, new { htmlfor = fullName, generated = true }), labelText, fullName);
        }
        #endregion

        #region helper methods
        private static IDictionary<string, object> PopulateClass(IDictionary<string, object> htmlAttributes, IEnumerable<string> values)
        {
            var existingData = string.Empty;
            if (htmlAttributes == null || htmlAttributes.Count == 0)
                htmlAttributes = new Dictionary<string, object>();
            else
            {
                if (htmlAttributes.ContainsKey("class"))
                {
                    existingData = htmlAttributes["class"].ToString();
                    htmlAttributes.Remove("class");
                }
            }

            existingData = values.Where(value => !string.IsNullOrEmpty(value)).Aggregate(existingData, (current, value) => current + (" " + value));

            htmlAttributes.Add("class", existingData);

            return htmlAttributes;
        }

        private static string GetMetadata(object[] attributes)
        {
            var metadata = "";
            var rules = new List<string>();
            var errorMessages = new List<string>();
            foreach (var attribute in attributes)
            {
                if (attribute is EmptyValidator)
                {
                    var att = (EmptyValidator)attribute;
                    if (!string.IsNullOrEmpty(att.ErrorMessage))
                    {
                        rules.Add("required:true,");
                        errorMessages.Add((errorMessages.Count() == 0 ? "" : ",") + "required:'{0}'".FormatWith(att.ErrorMessage));
                    }
                }
                if (attribute is EmailValidator)
                {
                    var att = (EmailValidator)attribute;
                    if (!string.IsNullOrEmpty(att.ErrorMessage))
                    {
                        rules.Add("email:true,");
                        errorMessages.Add((errorMessages.Count() == 0 ? "" : ",") + "email:'{0}'".FormatWith(att.ErrorMessage));
                    }
                }
                if (attribute is MaxLengthValidator)
                {
                    var att = (MaxLengthValidator)attribute;
                    if (!string.IsNullOrEmpty(att.ErrorMessage))
                    {
                        rules.Add("maxlength:" + att.MaximumLength + ",");
                        errorMessages.Add((errorMessages.Count() == 0 ? "" : ",") +
                                          "maxlength:'{0}'".FormatWith(att.ErrorMessage));
                        rules.Add("minlength:" + att.MinimumLength + ",");
                        errorMessages.Add((errorMessages.Count() == 0 ? "" : ",") +
                                          "minlength:'{0}'".FormatWith(att.ErrorMessage));
                    }
                }
                if (attribute is CompareAttribute)
                {
                    var att = (CompareAttribute)attribute;
                    if (!string.IsNullOrEmpty(att.ErrorMessage))
                    {
                        rules.Add("equalTo:'#" + att.OtherProperty + "',");
                        errorMessages.Add((errorMessages.Count() == 0 ? "" : ",") +
                                          "equalTo:'{0}'".FormatWith(att.ErrorMessage));
                    }
                }
                if (attribute is NumberValidator)
                {
                    var att = (NumberValidator)attribute;
                    if (!string.IsNullOrEmpty(att.ErrorMessage))
                    {
                        rules.Add("number:true,");
                        errorMessages.Add((errorMessages.Count() == 0 ? "" : ",") + "number:'{0}'".FormatWith(att.ErrorMessage));
                    }
                }
            }

            if (rules.Count > 0)
            {
                metadata = rules.Aggregate("{", (current, rule) => current + rule);
                metadata += " messages :{";
                metadata = errorMessages.Aggregate(metadata, (current, errorMessage) => current + errorMessage);
                metadata += "}}";
            }
            return metadata;
        }

        private static string Render(string formElement, string labelText, string labelFor)
        {
            string tpl;
            string output;

            if (string.IsNullOrEmpty(labelText))
            {
                tpl = "{0}";
                output = string.Format(tpl, formElement);
            }
            else
            {
                tpl = "<div class='looseTop clearfix'><label for='{0}'>{1}</label>{2}</div>";
                output = string.Format(tpl, labelFor, labelText, formElement);
            }

            return output;
        }
        #endregion

        #region Error Message Span
        public static string ErrorMessage(this HtmlHelper helper, string message)
        {
            if (string.IsNullOrEmpty(message))
                return string.Empty;

            var tagBuilder = new TagBuilder("span") { InnerHtml = message };
            tagBuilder.AddCssClass("field-validation-error");
            return tagBuilder.ToString(TagRenderMode.Normal);
        }
        #endregion
        #region DropDownList
        public static string DropDownList<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string labelText,
          IEnumerable<SelectListItem> selectList, string optionLabel, object selectedItem)
        {

            var selectedList = new List<SelectListItem>();
            foreach (var item in selectList)
            {
                item.Selected = item.Value == (selectedItem == null ? string.Empty : selectedItem.ToString());
                selectedList.Add(item);
            }
            return DropDownList(helper, property, labelText, selectedList, null, optionLabel, DropDownSize.Medium, null);
        }

        public static string DropDownList<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string labelText,
            IEnumerable<SelectListItem> selectList)
        {
            return DropDownList(helper, property, labelText, selectList, null, null, DropDownSize.Medium, null);
        }

        public static string DropDownList<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string labelText,
           IEnumerable<SelectListItem> selectList, string optionLabel, string overrideName)
        {
            return DropDownList(helper, property, labelText, selectList, null, optionLabel, DropDownSize.Medium, overrideName);
        }

        public static string DropDownList<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string labelText,
            IEnumerable<SelectListItem> selectList, string optionLabel)
        {
            return DropDownList(helper, property, labelText, selectList, null, optionLabel, DropDownSize.Medium, null);
        }

        public static string DropDownList<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string labelText,
            IEnumerable<SelectListItem> selectList, IDictionary<string, object> htmlAttributes)
        {
            return DropDownList(helper, property, labelText, selectList, htmlAttributes, null, DropDownSize.Medium, null);
        }

        public static string DropDownList<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string labelText,
            IEnumerable<SelectListItem> selectList, IDictionary<string, object> htmlAttributes, string optionLabel)
        {
            return DropDownList(helper, property, labelText, selectList, htmlAttributes, optionLabel, DropDownSize.Medium, null);
        }

        public static string DropDownList<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string labelText,
            IEnumerable<SelectListItem> selectList, DropDownSize size)
        {
            return DropDownList(helper, property, labelText, selectList, null, null, size, null);
        }

        public static string DropDownList<T>(this HtmlHelper helper, Expression<Func<T, object>> property,
            IEnumerable<SelectListItem> selectList, string optionLabel, DropDownSize size)
        {
            return DropDownList(helper, property, null, selectList, null, optionLabel, size, null);
        }
        public static string DropDownList<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string labelText,
          IEnumerable<SelectListItem> selectList, string optionLabel, DropDownSize size)
        {
            return DropDownList(helper, property, labelText, selectList, null, optionLabel, size, null);
        }

        public static string DropDownList<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string labelText,
            IEnumerable<SelectListItem> selectList, IDictionary<string, object> htmlAttributes, DropDownSize size)
        {
            return DropDownList(helper, property, labelText, selectList, htmlAttributes, null, size, null);
        }

        public static string DropDownList<T, TEnum>(this HtmlHelper helper, Expression<Func<T, object>> property, string labelText, IDictionary<string, object> htmlAttributes, DropDownSize size)
        {
            var values = from TEnum e in Enum.GetValues(typeof(TEnum))
                         select new { ID = e, Name = e.ToString() };

            return DropDownList(helper, property, labelText, new SelectList(values), htmlAttributes, null, size, null);
        }
        public static string DropDownList<T>(this HtmlHelper helper, Expression<Func<T, object>> property, string labelText,
            IEnumerable<SelectListItem> selectList, IDictionary<string, object> htmlAttributes, string optionLabel,
            DropDownSize size, string overrideName)
        {
            var info = ExpressionHelper.GetMemberInfo(property) as PropertyInfo;
            if (info == null) throw new ArgumentException("Member is not a property");

            var stringBuilder = new StringBuilder();
            var classValues = new string[2];
            classValues[0] = size.ToString().ToLowerInvariant();
            classValues[1] = GetMetadata(info.GetCustomAttributes(true));
            htmlAttributes = PopulateClass(htmlAttributes, classValues);

            if (string.IsNullOrEmpty(optionLabel))
                optionLabel = null;

            if (string.IsNullOrEmpty(overrideName))
            {
                stringBuilder.Append(helper.DropDownList(info.Name, selectList, optionLabel, htmlAttributes));
                stringBuilder.Append(helper.ValidationMessage(info.Name, new { htmlfor = info.Name, generated = true }));
                return Render(stringBuilder.ToString(), labelText, info.Name);
            }

            stringBuilder.Append(helper.DropDownList(overrideName, selectList, optionLabel, htmlAttributes));
            stringBuilder.Append(helper.ValidationMessage(overrideName, new { htmlfor = overrideName, generated = true }));
            return Render(stringBuilder.ToString(), labelText, overrideName);
        }
        #endregion
        public static string Language(this HtmlHelper helper)
        {
            return Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
        }

    }
}
